package january.test_1_18;

public class TestMain1 {
    public static void main(String[] args) {
        int[] arr = {2,7,9,3,1};
        System.out.println(massage(arr));
    }
    public static int massage(int[] nums) {
        int len = nums.length;
        if(len == 0) {
            return 0;
        }
        if(len == 1) {
            return nums[0];
        }
        int[] dp = new int[len + 1];
        dp[1] = nums[0];
        dp[2] = nums[1];
        for(int i = 3; i <= len ; i++) {
            int max = Math.max(dp[i-2],dp[i-3]);
            dp[i] = nums[i-1] + max;

        }
        return  Math.max(dp[len],dp[len-1]);
    }

}
